package com.yidu.hbats.service.impl.emp;

import com.github.pagehelper.PageHelper;
import com.yidu.hbats.dao.AtsEmpAthleteResultsMapper;
import com.yidu.hbats.service.emp.AtsEmpAthleteResultsService;
import com.yidu.utils.Page;
import com.yidu.hbats.model.AtsEmpAthleteResults;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: hbats
 * @description: 比赛成绩信息实现类
 * @author: 张超
 * @create: 2019-11-01 13:37
 */

@Service
public class AtsEmpAthleteResultsServiceImpl implements AtsEmpAthleteResultsService {

    @Resource
    AtsEmpAthleteResultsMapper atsEmpAthleteResultsMapper;

    @Override
    public int deleteAll(String ids) {
        if(StringUtils.isEmpty(ids)){
            return 0;
        }else{
            String[] idss = ids.split(",");
            for(int i = 0;i<idss.length;i++){
                AtsEmpAthleteResults atsEmpAthleteResults = new AtsEmpAthleteResults();
                atsEmpAthleteResults.setResultId(Integer.valueOf(idss[i]));
                atsEmpAthleteResults.setIsva(2);
                saveOrUpdate(atsEmpAthleteResults);
            }
            return 1;
        }
    }

    @Override
    public int saveOrUpdate(AtsEmpAthleteResults atsEmpAthleteResults) {
        if(StringUtils.isEmpty(atsEmpAthleteResults.getResultId())){
            atsEmpAthleteResultsMapper.insertSelective(atsEmpAthleteResults);
        }else{
            atsEmpAthleteResultsMapper.updateByPrimaryKeySelective(atsEmpAthleteResults);
        }
        return 0;
    }

    @Override
    public AtsEmpAthleteResults findById(Integer id) {
        return atsEmpAthleteResultsMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<AtsEmpAthleteResults> selectAll(AtsEmpAthleteResults atsEmpAthleteResults, Page page) {
        PageHelper.offsetPage(page.getStart(), page.getRows());

        List<AtsEmpAthleteResults> list = atsEmpAthleteResultsMapper.selectAll(atsEmpAthleteResults);

        PageHelper.startPage(page.getStart(), page.getRows());
        return list;
    }

    @Override
    public int selectCount(AtsEmpAthleteResults atsEmpLeader) {
        return atsEmpAthleteResultsMapper.selectCount(atsEmpLeader);
    }

    @Override
    public List<AtsEmpAthleteResults> findAll(AtsEmpAthleteResults atsEmpAthleteResults) {
        return atsEmpAthleteResultsMapper.findAll(atsEmpAthleteResults);
    }
}